package com.wedo.book.mapper;

import com.wedo.book.pojo.Chapter;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface ChapterMapper extends Mapper<Chapter> {

    @Select("SELECT max(sequence_num) FROM `chapter` where b_id = #{bid}")
    Integer queryMaxSequenceNumByBid(@Param("bid") Long bid);

    @Update("UPDATE chapter SET sequence_num=sequence_num+1 WHERE sequence_num > #{frontSequenceNum} and b_id = #{bid}")
    void updateSequenceNumLaterAdd(@Param("frontSequenceNum") Integer frontSequenceNum,@Param("bid") Long bid);

    @Update("UPDATE chapter SET sequence_num=sequence_num-1 WHERE sequence_num > #{frontSequenceNum} and b_id = #{bid}")
    void updateSequenceNumLaterSub(@Param("frontSequenceNum") Integer frontSequenceNum,@Param("bid") Long bid);
}
